package emby.experimental;
import java.util.concurrent.Callable;

import emby.err.RuntimeError;
import emby.expr.Variable;
import emby.lang.Block;
import emby.lang.EmbyFunction;
import emby.lang.Scope;
import jstlib.parallel.TaskManager;

/**
 * The 
 * @author Justin
 *
 */
public class EmbyParallelFunction extends EmbyFunction{
	
	public EmbyParallelFunction(String _name, Scope _definedScope, Block _b,
			Variable[] _params) {
		super(_name, _definedScope, _b, _params);
	}
	
	@Override
	public Object execute(final int lineNumber,final Scope s,final Object... args){
		Callable<Object> c = new Callable<Object>(){
			@Override
			public Object call() throws Exception {
				Object ret= _execute(lineNumber, s, args);
				return ret;
			}
		};
		EmbyReadableFuture<Object> rf = new EmbyReadableFuture<Object>(TaskManager.getInstance().submit(c));
		return rf;
		
	}

}
